package com.zsj.config.druid;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;

/**
 * Druid 数据源配置。主要的已经自动配置，如有特殊配置，可能写会在这里
 *
 * @author Zsj
 * @date 2020.04.29 
 */
@Configuration
public class DruidConfig {
	
    @Primary
    @Bean
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource getDataSource(){
        //return new DruidDataSource();
        return DruidDataSourceBuilder.create().build();
    }
    
    //------------------------------------- 配置多数据源 ------------------------------
    /*
     * 强烈注意：Spring Boot 2.X 版本不再支持配置继承，多数据源的话每个数据源的所有配置都需要单独配置，否则配置不会生效
     */
    @Bean
    @ConfigurationProperties("spring.datasource.druid.one")
    public DataSource dataSourceOne(){
        return DruidDataSourceBuilder.create().build();
    }
    
    @Bean
    @ConfigurationProperties("spring.datasource.druid.two")
    public DataSource dataSourceTwo(){
        return DruidDataSourceBuilder.create().build();
    }

}
